extends IBasicComponent


class_name EntryTrigger
"""
双向的触发器
"""


## 进入时触发
@export var enter_event: IEventActuator = null
## 退出时触发
@export var exit_event: IEventActuator = null


var __is_entered: bool = false


func __prepare() -> void:
    super.__prepare()

    if not enter_event and not exit_event:
        var nodes: Array = IComponent.find_children(self, func(x): return x is IEventActuator, [])
        if nodes.size() > 0:
            enter_event = nodes[0]
            exit_event = nodes[-1]

func __on_event_enter() -> void:
    if IComponent.is_available(self):
        __is_entered = true
        IEventActuator.safe_execute(enter_event)

func __on_event_exit() -> void:
    if IComponent.is_available(self):
        IEventActuator.safe_execute(exit_event)
        __is_entered = false
